<?php
namespace Kuoqi\Api\Weixin\Mp;
/**
 * 响应内容
 * Class Response
 * @package Kuoqi\Api\Weixin\Mp
 */
class Response{

    public $wxcallback = array();

    //响应内容，这两个字段是一定会存在的
    public $response_array = array('errcode'=>0,'message'=>'nothing to do');

    public function __construct($wxcallback){
        $this->wxcallback = $wxcallback;
    }

    //响应内容信息,以数组的形式
    public function toArray($extra = array()){
        //如果是以数组的方式响应的内容
        if(is_array($this->wxcallback)){
            if(isset($this->wxcallback['errcode'])){
                if($this->wxcallback['errcode']){
                    $this->response_array['errcode'] = $this->wxcallback['errcode'];
                    $this->response_array['message'] = $this->wxcallback['errmsg'];
                }else{
                    $this->response_array['errcode'] = $this->wxcallback['errcode'];
                    $this->response_array['message'] = $this->wxcallback['errmsg'];
                    unset($this->wxcallback['errcode'],$this->wxcallback['errmsg']);
                    $this->response_array['data'] = $this->wxcallback;
                    if($extra&&is_array($extra)){
                        $this->response_array['data'] = array_merge($this->response_array['data'],$extra);
                    }
                }
            }else{
                $this->response_array['errcode'] = 0;
                $this->response_array['message'] = 'ok';
                $this->response_array['data'] = $this->wxcallback;
                if($extra&&is_array($extra)){
                    $this->response_array['data'] = array_merge($this->response_array['data'],$extra);
                }
            }
        }
        return $this->response_array;
    }

}